package manager
{
	
	import model.*;
	
	/**
	 * -- ProxyMgr --
	 * @desc	proxy manager, used to initialize and supply proxies
	 * @author	Aqua (built on 2011-11-08)
	 */
	public class ProxyMgr
	{
		//---------------------//
		//      Singleton      //
		//---------------------//
		
		/**************************************************************************
		 * -- (getter) instance --
		 * @desc		get singleton of this class
		 * @return		singleton of this class
		 *************************************************************************/
		public static function get instance():ProxyMgr
		{
			if (null == _instance)
			{
				_instance = new ProxyMgr(singleton);
			}
		
			return _instance;
		}
		
		/**************************************************************************
		 * -- singleton --
		 * @desc		a private function used to enforce singlton
		 *************************************************************************/
		private static function singleton():void
		{
			
		}
		
		
		//---------------------//
		//     Constructor     //
		//---------------------//
		
		/**************************************************************************
		 * -- ProxyMgr --
		 * @desc		constructor
		 * @param		(s) a private function used to enforce singlton
		 *************************************************************************/
		public function ProxyMgr(s:Function = null):void
		{
			if (singleton != s)
			{
				throw new Error("This is a singleton class!");
			}
		}
		
		
		//-----------------//
		//     Publics     //
		//-----------------//
		
		/**************************************************************************
		 * -- init --
		 * @desc		initialize all proxies
		 *************************************************************************/
		public function init():void
		{
			var px:BasePx;
			
			_pxList = {};
			
			_pxList[UserPx.NAME]			= new UserPx();
			_pxList[CharacterPx.NAME]		= new CharacterPx();
			_pxList[ExplorePx.NAME]			= new ExplorePx();
			_pxList[DuelPx.NAME]			= new DuelPx();
			_pxList[BattlePx.NAME]			= new BattlePx();
			_pxList[CompoundPx.NAME]		= new CompoundPx();
			_pxList[ReinforceSkillPx.NAME]	= new ReinforceSkillPx();
			_pxList[ReinforceEquipPx.NAME]	= new ReinforceEquipPx();
			_pxList[ShopPx.NAME]			= new ShopPx();
			_pxList[RankPx.NAME]			= new RankPx();
			_pxList[CampPx.NAME]			= new CampPx();
			
			for each (px in _pxList)
			{
				px.init();
			}
		}
		
		/**************************************************************************
		 * -- getProxy --
		 * @desc		get instance of a specified proxy
		 * @param		(name) name of the proxy
		 * @return		instance of the proxy
		 *************************************************************************/
		public function getProxy(name:String):BasePx
		{
			if (! _pxList[name])
			{
				throw new Error("Wrong name of proxy!");
			}
			
			return _pxList[name];
		}
		
		
		//------------------//
		//     Privates     //
		//------------------//
		
		
		private static var _instance:ProxyMgr;
		
		private var _pxList	:Object;
	}
	
}